{{- $enable := and (default true .Params.toc) (default true .Site.Params.toc) -}}
{{- $wordCount := default 280 .Site.Params.tocWordCount -}}
{{- $toc := .TableOfContents -}}
{{- $valid := and $toc (and (ne $toc "<nav id=\"TableOfContents\"></nav>") (gt .WordCount $wordCount)) -}}
{{- if and $enable $valid -}}
{{- $sticky := default true .Site.Params.tocSticky -}}
<div class="accordion accordion-flush surface post-toc{{ if $sticky }} position-sticky{{ end }}" id="accordionTOC">
  <div class="accordion-item">
    <div class="accordion-header" id="headingTOC" data-toggle="collapse" data-target="#collapseTOC" aria-expanded="true" aria-controls="collapseTOC">
      <i class="fas fa-fw fa-bars"></i>{{ i18n "table_of_contents" }}
    </div>
    <div id="collapseTOC" class="accordion-collapse collapse" aria-labelledby="headingTOC" data-parent="#accordionTOC">
      <div class="accordion-body mt-2">
        {{ $toc }}
      </div>
    </div>
  </div>
</div>
{{- end -}}
